# -*- coding: utf-8 -*-
__author__ = 'SaGan'

from flask import render_template
from movie.models import db
from movie.models import Timeline
from . import timeline


@timeline.route("/<int:page>/", methods=['GET'])
def index(page=None):
    if page is None:
        page = 1
    page_data = Timeline.query.order_by(Timeline.add_time.desc(), Timeline.id.desc()).paginate(page=page, per_page=20)
    if len(page_data.items) < 20:
        page_data = Timeline.query.order_by(Timeline.add_time.asc(), Timeline.id.asc()).paginate()
    return render_template("timeline/index.html", page_data=page_data)
